package com.ymatou.iapi.godmch.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.utils.TestDataManager;
/**
*创建邀请码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CreateCode{
	private static CreateCodeBean bean;
	private static CreateCodeCall call;
	private  createmchBean createmchbean=new createmchBean();
	private  createmchCall createmchcall=new createmchCall();
	 public  agent_typeWapper agentTypeWapper=new agent_typeWapper();
	 private invite_codeWapper inviteCodeWapper=new invite_codeWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建邀请码");
	}

	@Before
	public void caseUp() {
		bean=new CreateCodeBean();
		call=new CreateCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/*
	 * 20200514修改
	 * 原有逻辑：落地的代理模式字段从请求落地
	 * 现有逻辑：从代理类型上查询到代理模式落地
	 * 所以现在 AgentModel的作用不大，为了兼容前端老内容，故 没有删除
	 */
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_001() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理-自主选货");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setAgentModel(1);//新增字段
			call.setData(bean);
			call.callService();

			//验证点
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(true, call.getCode().length()==6, "验证返回成功Code的长度等于6位");
	        
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        Logger.verifyIsNull(model.getExpireTime(), "验证数据表ExpireTime的值");
	        
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表CodeRole的值");//新增字段
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_001_1() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理-自动继承（返回失败 20200318 修改不支持自动继承）");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setAgentModel(2);//新增字段
			call.setData(bean);
			call.callService();
			//验证点
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("抱歉，平台商户不支持继承型代理"), "验证返回成功Message值");
	        
			//invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	       /* Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(true, call.getCode().length()==6, "验证返回成功Code的长度等于6位");
	        
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        Logger.verifyIsNull(model.getExpireTime(), "验证数据表ExpireTime的值");
	        
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表CodeRole的值");//新增字段
*/	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_002() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理,创建两次，返回第二次错误,提示:同一代理类型的永久有效期邀请码，只能创建一次(2020091修改,sit环境配置5)");
		try {
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			call.setData(bean);
			call.callService();	
			call.callService();	
			
			//验证点
	        Logger.verifyEquals("5010", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("同一代理类型的永久有效期邀请码，只能创建一次"), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	//@Ignore
	public void Tc_CreateCode_003() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是客服,返回错误,提示:只能创建一次性邀请码，不可设置永久有效期（目前 邀请客服不需要邀请码，后期可能需要）");
		try {
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setMchId(bean.getMchId());
			bean.setCodeRole(2);
			bean.setRoleType(2);
			bean.setIsPermanently(false);

			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_004() {
		Logger.start(true,"创建邀请码,验证创建不是永久用效-未过期-被邀请对象是代理(非永久类型的邀请码，根据配置文件设置有效期，有效期=创建时间 + 配置文件小时数,目前配置24小时)");
		try {
			int userId=GodmchManageCallService.UserCreateAgent();
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId);
			GodmchManageCallService.createmchCallForChannel(createBean);
			// 头像必要
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId);
			GodmchManageCallService.editmachCall(editmchbean);
            //渠道商
			createmchbean.setMchId(userId);
			createmchbean.setCountry("USA");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			
			//创建代理类型
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(userId);
			createagentCall createagentcall=GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			//获取代理
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId);
			List<agent_type> list=agentTypeWapper.selectby(map);
			bean.setMchId(userId);
			bean.setCodeRole(1);
			bean.setRoleType(list.get(0).getAgentType());//代理类型(如：北京代理，上海代理)
			bean.setIsPermanently(false);
			call.setData(bean);
			call.callService();
			//验证点
//			invite_code model=inviteCodeWapper.selectByPrimaryKey(Integer.parseInt(call.getCode()));
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        
	        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        java.util.Calendar Cal=java.util.Calendar.getInstance();   
	        Cal.setTime(model.getCreateTime());   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,1);  //目前配置一天后过期 
	        Logger.verifyEquals(true,(model.getExpireTime().getTime()-Cal.getTime().getTime())<5000, "验证数据表ExpireTime的值");		
			Logger.comment("getExpireTime:###########"+model.getExpireTime().getTime());
			Logger.comment("getTime:###########"+model.getExpireTime().getTime());
			Logger.comment("###########"+(model.getExpireTime().getTime()-Cal.getTime().getTime()));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_005() {
		Logger.start(true,"创建邀请码,验证创建不是永久用效-未过期-被邀请对象是客服(非永久类型的邀请码，根据配置文件设置有效期，有效期=创建时间 + 配置文件小时数,目前配置24小时)（目前 邀请客服不需要邀请码，后期可能需要）");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_006() {
		Logger.start(true,"创建邀请码,验证创建不是永久用效-被邀请对象是代理,创建多个");
		try {
			CreateCodeCall call1=new CreateCodeCall();
			CreateCodeCall call2=new CreateCodeCall();
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(false);
			call1.setData(bean);
			call2.setData(bean);
			call1.callService();
			call2.callService();			
			
	        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        java.util.Calendar Cal=java.util.Calendar.getInstance();   

	        
			//验证点
//			invite_code model=inviteCodeWapper.selectByPrimaryKey(Integer.parseInt(call1.getCode()));
			invite_code model=inviteCodeWapper.selectByCode(call1.getCode());
	        Logger.verifyEquals("200", call1.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call1.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call1.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call1.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        Cal.setTime(model.getCreateTime());   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,1);  //目前配置一天后过期 
	        Logger.verifyEquals(true,(model.getExpireTime().getTime()-Cal.getTime().getTime())<5000, "验证数据表ExpireTime的值");	
	        
	        
			invite_code model2=inviteCodeWapper.selectByCode(call2.getCode());
	        Logger.verifyEquals("200", call2.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call2.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call2.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model2.getInviteCode(), call2.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model2.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model2.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model2.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model2.getState(), "验证数据表State的值");
	        Cal.setTime(model2.getCreateTime());   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,1);  //目前配置一天后过期 
	        Logger.verifyEquals(true,(model2.getExpireTime().getTime()-Cal.getTime().getTime())<5000, "验证数据表ExpireTime的值");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_007() {
		Logger.start(true,"创建邀请码,验证创建不是永久用效-已过期-被邀请对象是客服（目前 邀请客服不需要邀请码，后期可能需要）");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_011() {
		Logger.start(true,"创建邀请码,验证创建永久用效-商户Id为空，返回错误");
		try {
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setMchId(null);
			bean.setCodeRole(1);
			bean.setRoleType(bean.getRoleType());
			bean.setIsPermanently(true);
			
			call.setData(bean);
			call.callService();
					
	        Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("商户id不能为空"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_012() {
		Logger.start(true,"创建邀请码,验证创建永久用效-代理类型为空，返回错误");
		try {
			int userId=GodmchManageCallService.UserCreateAgent();
            //渠道商
			createmchbean.setMchId(userId);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("自动化测试昵称");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			
			bean.setMchId(userId);
			bean.setCodeRole(1);
			bean.setRoleType(null);//代理类型(如：北京代理，上海代理)
			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			//验证点
	        Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("roleType不能为空"), "验证返回成功Message值");
	        
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_013() {
		Logger.start(true,"创建邀请码,验证代理商不能创建邀请码(业务更改，国家编号是 中国，就是纯代理，国外代理也有渠道身份)");
		try {
			//渠道商 a
			int userId_a=GodmchManageCallService.UserCreateAgent();//a
			createmchbean.setMchId(userId_a);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("自动化测试昵称");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_a);
			GodmchManageCallService.editmachCall(editmchbean);
			//渠道商 a 邀请码
			CreateCodeBean createCodeBean_a=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_a);
			CreateCodeCall createcall_a=GodmchManageCallService.createCodeCall(createCodeBean_a);
			//a代理b
			int userId_b=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId_b);
			createmchbean.setCountry("CHN");
			createmchbean.setNickName("自动化测试昵称");
			createmchbean.setCode(createcall_a.getCode());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			 editmchbean = GodmchManageCallService.IniteditmachBean(userId_b);
			GodmchManageCallService.editmachCall(editmchbean);
			//b 创建代理类型
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(userId_b);
			GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			//b 创建邀请码
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId_b);
			List<agent_type> list=agentTypeWapper.selectby(map);
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setRoleType(list.get(0).getAgentType());//代理类型(如：北京代理，上海代理)
			
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			//验证点
	        Logger.verifyEquals("5026", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("纯代理商禁止创建邀请码"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_014() {
		Logger.start(true,"创建邀请码,验证vip代理 创建永久用效-被邀请对象是vip代理");
		try {
			
			//渠道商 a
			int userId_a=GodmchManageCallService.UserCreateAgent();//a
			createmchbean.setMchId(userId_a);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("自动化测试昵称");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_a);
			GodmchManageCallService.editmachCall(editmchbean);
			GodmchManageCallService.SetVip(userId_a);
			//渠道商 a 邀请码
			CreateCodeBean createCodeBean_a=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_a);
			CreateCodeCall createcall_a=GodmchManageCallService.createCodeCall(createCodeBean_a);
			//a代理b
			int userId_b=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId_b);
			createmchbean.setCountry("CHN");
			createmchbean.setNickName("自动化测试昵称");
			createmchbean.setCode(createcall_a.getCode());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			 editmchbean = GodmchManageCallService.IniteditmachBean(userId_b);
			GodmchManageCallService.editmachCall(editmchbean);
			//b 创建代理类型
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(userId_b);
			GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			//b 创建邀请码
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId_b);
			List<agent_type> list=agentTypeWapper.selectby(map);
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setRoleType(list.get(0).getAgentType());//代理类型(如：北京代理，上海代理)
			
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			//验证点
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        Logger.verifyIsNull(model.getExpireTime(), "验证数据表ExpireTime的值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_015() {
		Logger.start(true,"创建邀请码,验证vip代理 创建非永久用效-被邀请对象是vip代理");
		try {
			//渠道商 a
			int userId_a=GodmchManageCallService.UserCreateAgent();//a
			createmchbean.setMchId(userId_a);
			createmchbean.setCountry("USA");
			createmchbean.setNickName("自动化测试昵称");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_a);
			GodmchManageCallService.editmachCall(editmchbean);
			GodmchManageCallService.SetVip(userId_a);
			//渠道商 a 邀请码
			CreateCodeBean createCodeBean_a=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_a);
			CreateCodeCall createcall_a=GodmchManageCallService.createCodeCall(createCodeBean_a);
			//a代理b
			int userId_b=GodmchManageCallService.UserCreateAgent();
			createmchbean.setMchId(userId_b);
			createmchbean.setCountry("CHN");
			createmchbean.setNickName("自动化测试昵称");
			createmchbean.setCode(createcall_a.getCode());
			createmchcall.setData(createmchbean);
			createmchcall.callService();
			 editmchbean = GodmchManageCallService.IniteditmachBean(userId_b);
			GodmchManageCallService.editmachCall(editmchbean);
			//b 创建代理类型
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(userId_b);
			GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			//b 创建邀请码
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId_b);
			List<agent_type> list=agentTypeWapper.selectby(map);
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setRoleType(list.get(0).getAgentType());//代理类型(如：北京代理，上海代理)
			
			bean.setMchId(userId_b);
			bean.setCodeRole(1);
			bean.setIsPermanently(false);
			call.setData(bean);
			call.callService();
			//验证点
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        
	        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	        java.util.Calendar Cal=java.util.Calendar.getInstance();   
	        Cal.setTime(model.getCreateTime());   
	        Cal.add(java.util.Calendar.DAY_OF_YEAR,1);  //目前配置一天后过期 
	        Logger.verifyEquals(true,(model.getExpireTime().getTime()-Cal.getTime().getTime())<5000, "验证数据表ExpireTime的值");		
			Logger.comment("getExpireTime:###########"+model.getExpireTime().getTime());
			Logger.comment("getTime:###########"+model.getExpireTime().getTime());
			Logger.comment("###########"+(model.getExpireTime().getTime()-Cal.getTime().getTime()));
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_0016() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理-验证已经创建过永久的邀请码(2020091修改,sit环境配置5)");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			
			Map<String,Object> map=new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			
			bean.setMchId(bean.getMchId());
			bean.setCodeRole(1);
			//bean.setRoleType(list.get(0).getAgentType());
			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			call.callService();
			//验证点
	        Logger.verifyEquals("5010", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("同一代理类型的永久有效期邀请码，只能创建一次"), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateCode_017() {
		Logger.start(false,"创建邀请码,验证多个上级渠道-自动继承(只允许 纯渠道 才可以设置 自动继承)(返回失败,20200318修改，不支持自动继承)");
		//20200514 修改 从代理类型上查询到代理模式落地
		try {
			
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int userId1 = DGUserCallService.UserCreateCall(usercreateBean2);
		     usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(createBean);
			
			createmchBean createBean2=GodmchManageCallService.InitcreatemchBeanForChannel(userId2);
			GodmchManageCallService.createmchCallForChannel(createBean2);
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId1, true);
			//createCodeBean.setAgentModel(1);
			CreateCodeCall codeCal=GodmchManageCallService.createCodeCall(createCodeBean);
			
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(userId2, codeCal.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			
			// 头像必要
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId1);
			GodmchManageCallService.editmachCall(editmchbean);
			
			// 头像必要
			editmchbean = GodmchManageCallService.IniteditmachBean(userId2);
			GodmchManageCallService.editmachCall(editmchbean);
            //渠道商
			createmchbean.setMchId(userId1);
			createmchbean.setCountry("USA");
			createmchcall.setData(createmchbean);
			createmchcall.callService();	
			
		
			//获取代理
			Map<String,Object> map=new HashMap();
			map.put("mchId", userId2);
			List<agent_type> list=agentTypeWapper.selectby(map);
			bean.setMchId(userId2);
			bean.setCodeRole(1);
			bean.setRoleType(list.get(0).getAgentType());//代理类型(如：北京代理，上海代理)
			bean.setAgentModel(2);//代理模式 1自主选货，2.自动继承
			bean.setIsPermanently(false);
			call.setData(bean);
			call.callService();

			//验证点
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("抱歉，平台商户不支持继承型代理"), "验证返回成功Message值");
	        
	       /* Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("抱歉，您同时代理了其他渠道商的商品，因此无法创建继承型代理"), "验证返回成功Message值");*/
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_0018() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理-代理类型自主选货");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(bean.getMchId());
			createagentBean.setAgentMode(1);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
			createagentCall createagentCall=GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			Map<String, Object> map = new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list = agentTypeWapper.selectby(map);
			
			bean.setRoleType(list.get(2).getAgentType());
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setAgentModel(2);//新增字段
			call.setData(bean);
			call.callService();
			
			//验证点
			invite_code model=inviteCodeWapper.selectByCode(call.getCode());
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
	        Logger.verifyEquals(model.getInviteCode(), call.getCode(), "验证返回成功Code值");
	        Logger.verifyEquals(bean.getCodeRole(),model.getCodeRole(), "验证数据表invite_code的值");
	        Logger.verifyEquals(bean.getRoleType(),model.getRoleType(), "验证数据表RoleType的值");
	        Logger.verifyEquals(bean.getMchId(),model.getMchId(), "验证数据表MchId的值");
	        Logger.verifyEquals(0,model.getState(), "验证数据表State的值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_0019() {
		Logger.start(true,"创建邀请码,验证创建永久用效-被邀请对象是代理-代理类型自动继承-返回失败");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			
			createagentBean createagentBean=GodmchManageCallService.InitCreateAgentTypeBean(bean.getMchId());
			createagentBean.setAgentMode(2);
			createagentCall createagentCall=GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			Map<String, Object> map = new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list = agentTypeWapper.selectby(map);
			
			bean.setRoleType(list.get(2).getAgentType()); 
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setAgentModel(2);//新增字段
			call.setData(bean);
			call.callService();
			//验证点
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("抱歉，平台商户不支持继承型代理"), "验证返回成功Message值");
	           
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_019() {
		Logger.start(true,"创建邀请码,验证自动继承的代理商禁止创建自动继承类型的邀请码-修改20200519");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			GodmchManageCallService.SetVip(mchId);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			//createagentBean.setAgentMode(1);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);

			Thread.sleep(5000);
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			//代理邀请码
			Integer agentId=registerByCodeCall.getRegMchId();
			createagentBean createagentBean2=GodmchManageCallService.InitCreateAgentTypeBean(agentId);
			createagentBean2.setAgentMode(2);//
			createagentBean2.setRebateRate(new BigDecimal(30));
			createagentCall createagentCall2=GodmchManageCallService.CreateAgentTypeCall(createagentBean2);
			//代理code
			 bean=GodmchManageCallService.InitcreateCodeBeanForAgent(agentId, true);
			
			
			//查询类型
			 agentTypewapper = new agent_typeWapper();
			 map = new HashMap();
			map.put("mchId", mchId);
			agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());

			call=GodmchManageCallService.createCodeCall(bean);
			//验证点
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("自动继承型代理商无法再招募自动继承的代理商"), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_020() {
		Logger.start(true,"创建邀请码,验证非Vip-代理是自动继承的纯代理商禁止创建邀请码-修改20200519");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			//GodmchManageCallService.SetVip(mchId);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			//createagentBean.setAgentMode(1);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);

			Thread.sleep(5000);
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			//代理邀请码
			Integer agentId=registerByCodeCall.getRegMchId();
			createagentBean createagentBean2=GodmchManageCallService.InitCreateAgentTypeBean(agentId);
			createagentBean2.setAgentMode(2);//
			createagentBean2.setRebateRate(new BigDecimal(30));
			createagentCall createagentCall2=GodmchManageCallService.CreateAgentTypeCall(createagentBean2);
			//代理code
			 bean=GodmchManageCallService.InitcreateCodeBeanForAgent(agentId, true);
			
			
			//查询类型
			 agentTypewapper = new agent_typeWapper();
			 map = new HashMap();
			map.put("mchId", mchId);
			agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());

			call=GodmchManageCallService.createCodeCall(bean);
			//验证点
			Logger.verifyEquals("5026", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals(true, call.getMessage().contains("纯代理商禁止创建邀请码"), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_021() {
		Logger.start(true,"创建邀请码,验证创建永久用效-同一代理类型永久代理邀请码最大数量为5-sit目前disconfig配置5");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setAgentModel(1);//新增字段
			call.setData(bean);
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			
	        Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("同一代理类型的永久邀请码最多可创建5个", call.getMessage(), "验证返回成功Message值");
			
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_022() {
		Logger.start(true,"创建邀请码,验证创建永久用效-同一代理类型-非永久4，永久2-返回成功");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(false);
			call.setData(bean);
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			
			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			call.callService();
			
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	    //    Logger.verifyEquals("同一代理类型的永久邀请码最多可创建5个", call.getMessage(), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateCode_023() {
		Logger.start(true,"创建邀请码,验证创建永久用效-创建多代理类型-返回成功");
		try {
			
			bean=GodmchManageCallService.CreateAllMsgSellerMch();
			bean.setCodeRole(1);
			bean.setIsPermanently(false);
			call.setData(bean);
			call.callService();
			call.callService();

			bean.setIsPermanently(true);
			call.setData(bean);
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			call.callService();
			
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(bean.getMchId());
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			Map<String, Object> map = new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list = agentTypeWapper.selectby(map);
			
			bean.setCodeRole(1);
			bean.setIsPermanently(true);
			bean.setRoleType(list.get(1).getAgentType());
			call.setData(bean);
			call.callService();
			
	        Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	    //    Logger.verifyEquals("同一代理类型的永久邀请码最多可创建5个", call.getMessage(), "验证返回成功Message值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

}